﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRM.WEB.Pub
{
    public partial class DownLoad : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string FilePath = HttpContext.Current.Server.MapPath("~");  //获取项目绝对路径
            FilePath = FilePath.Substring(0, FilePath.LastIndexOf("\\", System.StringComparison.Ordinal));
            string strFilePath = Request.QueryString["path"];
            strFilePath = Path.Combine(FilePath, strFilePath.TrimStart('/'));
            if (File.Exists(strFilePath))
            {
                FileInfo DownloadFile = new FileInfo(strFilePath);
                base.Response.Clear();
                base.Response.ClearHeaders();
                base.Response.Buffer = false;
                base.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.Name));
                base.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
                base.Response.ContentType = "application/zip";
                base.Response.WriteFile(strFilePath);
                base.Response.Flush();
                base.Response.End();
            }
            else
            {
                base.Response.Write("<script langauge=javascript>alert('文件不存在!');window.opener=null;window.close();</script>");
                base.Response.End();
            }
        }
    }
}